package com.cc.controller;

import com.cc.model.EbProduct;
import com.cc.model.EbProductCategory;
import com.cc.service.NewsService;
import com.cc.service.ProductCategoryService;
import com.cc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/*控制器*/
@Controller
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private ProductService productService ;
    @Autowired
    private NewsService newsService;
    @Autowired
    private ProductCategoryService productCategoryService;

    @RequestMapping("/manage")
    public String indexManage(){
        //返回给浏览器的需要访问的页面的路径
        //spring-web.xml中配置了页面的路径前缀和后缀
        //"/WEB-INF/manage/index.jsp"
        return "manage/index";
    }
    @RequestMapping("/front")
    public String index(Model model){

        //1.分类信息
        //1.1 大类集合
        List<EbProductCategory> bigs = productCategoryService.bigProductCategorys();
        model.addAttribute("bigs",bigs);
        //1.2 小类的集合
        List<EbProductCategory> smalls = productCategoryService.smallProductCategorys();
        model.addAttribute("smalls",smalls);

        //2.分页查询商品信息
        List<EbProduct> productList =  productService.list(1,8);
        model.addAttribute("products",productList);
        //3.分页查询新闻信息

        return "index";
    }



}
